package org.jeecg.modules.yks.job;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.dto.message.BusMessageDTO;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.yks.config.MqttConfig;
import org.jeecg.modules.yks.dev.entity.YksEquipment;
import org.jeecg.modules.yks.dev.entity.YksEquipmentDevops;
import org.jeecg.modules.yks.dev.service.IYksEquipmentService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class AutoRefreshMqttListenJob implements Job {
    @Autowired
    private IYksEquipmentService yksEquipmentService;
    @Autowired
    private MqttConfig mqttConfig;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        log.info(String.format(" Jeecg-Boot 发送消息任务 AutoRefreshMqttListenJob !  时间:" + DateUtils.getTimestamp()));
        // 1.读取运维数据，只查询当天未运维的数据
        QueryWrapper<YksEquipment> queryWrapper = new QueryWrapper<YksEquipment>();
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        //queryWrapper.eq("maintenance_next_time", DateUtils.formatDate()).lt("maintenance_status",1);
        List<YksEquipment> yksEquipments = yksEquipmentService.list(queryWrapper);
        System.out.println(yksEquipments);
        List<String> rdees=new ArrayList<>();
        // 2.根据不同的类型走不通的发送实现类
        for (YksEquipment yksEquipment : yksEquipments) {
            if(yksEquipment.getRdeeId()!=null&&!yksEquipment.getRdeeId().isEmpty())
            {
                log.info(String.format(" Jeecg-Boot 发送消息任务 AutoRefreshMqttListenJob/dtu/113100033552/data !RdeeId："+yksEquipment.getRdeeId()+"  时间:" + DateUtils.getTimestamp()));
                rdees.add("/dtu/"+yksEquipment.getRdeeId()+"/data");
            }
        }
        mqttConfig.addListenTopic(rdees.toArray(new String[0]));
    }
}
